package zozopo.business;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.comm.Validate;
import zozopo.operations.business.StoreOS;
import zozopo.operations.business.StoreTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ModifyStoreAction extends ActionSupport implements Action,SessionAware{
	private Map<Object, Object> session;
	
	private int id;
	private String url;
	private String image;
	private String name;
	private String shortname;
	private String content;
	private String brand;
	private String enbrand;
	private String cnbrand;
	private String cnspell;
	private Integer flow;
	private Integer star;
	private Integer star1;
	private Integer star2;
	private Integer star3;
	private Integer star4;
	private Integer star5;
	private Integer star6;
	private Integer star7;
	private Integer star8;
	private Integer star9;
	private Integer star10;
	private String status;
	private String kind;
	private String lable;
	
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	public String execute(){

		StoreOS storeOS = new StoreOS();
		StoreTB store = new StoreTB();
		
		store.setBrand_store(brand);
		//store.setCnbrand_store(cnbrand_)
		store.setCnbrand_store(cnbrand);
		
		content = content.replaceAll("'", "\\\\'");
		content = Validate.htmlLabelFilter(content);
		
		store.setContent_store(content);
		store.setEnbrand_store(enbrand);
		//store.setFlow_store(flow_store)
		store.setImage_store(image);
		//store.setKind_store(kind);
		store.setShortname_store(shortname);
		store.setLable_store(lable);
		store.setName_store(name);
		store.setStar_store(star);
		store.setUrl_store(url);
		store.setId_store(id);
		
		if(storeOS.upadteStore(store)){
			storeOS.releaseConnection();
			return SUCCESS;
		}else{
			storeOS.releaseConnection();
			return ERROR;
		}
	}
	

	public void validate() {
		// TODO Auto-generated method stub
		 
		UserTB user = (UserTB) session.get("userInfo");
		if(user == null){
			addFieldError("errormessage", "请登陆后再进行操作");
			return;
		}
		
		if(!UserOS.userFlagLeve(user, 4, 1)){
			addFieldError("errormessage", "权限不足请与管理员联系");
			return;
		}
		
		if(name == null || name.trim().equals("")){
			addFieldError("errormessage", "网店名称不能为空");
			return;
		}
		
		if(Validate.isSpecialCharacters(name)){
			addFieldError("errormessage", "标题长度不能包含特殊字符 ;\"'\\`|$");
			return;
		}
		
		if(url == null || url.trim().equals("")){
			addFieldError("errormessage", "网店连接不能为空");
			return;
		}
		
		/*if(brand == null || brand.trim().equals("")){
			addFieldError("errormessage", "经营品牌不能为空");
			return;
		}*/
		
		if(Validate.isSpecialCharacters(brand)){
			addFieldError("errormessage", "品牌长度不能包含特殊字符  ;\"'\\`|$");
			return;
		}
		
		if(lable == null || lable.trim().equals("")){
			lable="MANUAL.LABLE.OTHER";
		}
		/*
		StoreOS storeOS = new StoreOS();
		
		
		if(storeOS.isExistUrl(url)){
			addFieldError("errormessage", "URL已经存在不可以发重复URL连接!");
			storeOS.releaseConnection();
			return;
		}
		
		storeOS.releaseConnection();
		
		
		}
		
		*/
		
		
		
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public String getUrl() {
		return url;
	}


	public void setUrl(String url) {
		this.url = url;
	}


	public String getImage() {
		return image;
	}


	public void setImage(String image) {
		this.image = image;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getContent() {
		return content;
	}


	public void setContent(String content) {
		this.content = content;
	}


	public String getBrand() {
		return brand;
	}


	public void setBrand(String brand) {
		this.brand = brand;
	}


	public String getEnbrand() {
		return enbrand;
	}


	public void setEnbrand(String enbrand) {
		this.enbrand = enbrand;
	}


	public String getCnbrand() {
		return cnbrand;
	}


	public void setCnbrand(String cnbrand) {
		this.cnbrand = cnbrand;
	}


	public String getCnspell() {
		return cnspell;
	}


	public void setCnspell(String cnspell) {
		this.cnspell = cnspell;
	}


	public Integer getFlow() {
		return flow;
	}


	public void setFlow(Integer flow) {
		this.flow = flow;
	}


	public Integer getStar() {
		return star;
	}


	public void setStar(Integer star) {
		this.star = star;
	}


	public Integer getStar1() {
		return star1;
	}


	public void setStar1(Integer star1) {
		this.star1 = star1;
	}


	public Integer getStar2() {
		return star2;
	}


	public void setStar2(Integer star2) {
		this.star2 = star2;
	}


	public Integer getStar3() {
		return star3;
	}


	public void setStar3(Integer star3) {
		this.star3 = star3;
	}


	public Integer getStar4() {
		return star4;
	}


	public void setStar4(Integer star4) {
		this.star4 = star4;
	}


	public Integer getStar5() {
		return star5;
	}


	public void setStar5(Integer star5) {
		this.star5 = star5;
	}


	public Integer getStar6() {
		return star6;
	}


	public void setStar6(Integer star6) {
		this.star6 = star6;
	}


	public Integer getStar7() {
		return star7;
	}


	public void setStar7(Integer star7) {
		this.star7 = star7;
	}


	public Integer getStar8() {
		return star8;
	}


	public void setStar8(Integer star8) {
		this.star8 = star8;
	}


	public Integer getStar9() {
		return star9;
	}


	public void setStar9(Integer star9) {
		this.star9 = star9;
	}


	public Integer getStar10() {
		return star10;
	}


	public void setStar10(Integer star10) {
		this.star10 = star10;
	}


	public String getStatus() {
		return status;
	}


	public void setStatus(String status) {
		this.status = status;
	}


	public String getKind() {
		return kind;
	}


	public void setKind(String kind) {
		this.kind = kind;
	}


	public String getLable() {
		return lable;
	}


	public void setLable(String lable) {
		this.lable = lable;
	}

	public String getShortname() {
		return shortname;
	}

	public void setShortname(String shortname) {
		this.shortname = shortname;
	}
}
